﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlServerCe;
using System.IO;
using System.Windows.Forms;

namespace Modelo_ETdA.Dados
{
    public class AdminBD
    {

        private static string dataSource;
        private static string appPath;
        private static string password;
        private static SqlCeConnection coneCe;

        public AdminBD()
        {
            appPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ETdA\\";
            dataSource = "etda_db.sdf";
            password = "etda_password";
        }

        public static bool conectarBaseDados()
        {
            coneCe = new SqlCeConnection("Data Source=" + appPath + dataSource + ";Password=" + password);
            try
            {
                coneCe.Open();
            }
            catch (SqlCeException e)
            {
                Console.WriteLine(e.ToString());
                return true;
            }
            return false;
        }
        public static void desconectarBaseDados()
        {
            try
            {
                coneCe.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        public static SqlCeConnection getConCe()
        {
            return coneCe;
        }

        public static string DataSource
        {
            get { return AdminBD.dataSource; }
        }

        public static void gerarBackup(String caminho)
        {
            File.Copy(appPath + dataSource, caminho, true);
        }

        public static void carregaBackup(String caminho)
        {
            File.Copy(caminho, appPath + dataSource, true);
        }
    }
}

